Java EE 7 Essentials by Arun Gupta
Author:Arun Gupta [Arun Gupta]
Language: eng
Format: epub, pdf
Tags: COMPUTERS / Programming Languages / Java
ISBN: 9781449370169
Publisher: O’Reilly Media
Published: 2013-08-08T16:00:00+00:00
Events
Events provide an annotation-based event model based upon the observer pattern. Event producers raise events that are consumed by observers. The event object, typically a POJO, carries state from producer to consumer. The producer and the observer are completely decoupled from each other and only communicate using the state.
A producer bean will fire an event using the Event interface:
@Inject @Any Event<Customer> event; //. . . event.fire(customer);
An observer bean with the following method signature will receive the event:
void onCustomer(@Observes Customer event) { //. . . }
In this code, Customer is carrying the state of the event.
The producer bean can specify a set of qualifiers when injecting the event:
@Inject @Any @Added Event<Customer> event;
The observer bean’s method signature has to match the exact set of qualifiers in order to receive the events fired by this bean:
void onCustomer(@Observes @Added Customer event) { //. . . }
Qualifiers with parameters and multiple qualifiers may be specified to further narrow the scope of an observer bean.
By default, an existing instance of the bean or a new instance of the bean is created in the current context to deliver the event. This behavior can be altered so that the event is delivered only if the bean already exists in the current scope:
void onCustomer( @Observes( notifyObserver= Reception.IF_EXISTS) @Added Customer event){ //. . . }
Transactional observer methods receive their event notifications during the before completion or after completion phases of the transaction in which the event was fired. TransactionPhase identifies the kind of transactional observer methods, as defined in Table 9-6.
Table 9-6. Transactional observers
Transactional observersDescription
IN_PROGRESS Default behavior; observers are called immediately
BEFORE_COMPLETION Observers are called during the before completion phase of the transaction
AFTER_COMPLETION Observers are called during the after completion phase of the transaction
AFTER_FAILURE Observers are called during the after completion phase of the transaction, only when the transaction fails
AFTER_SUCCESS Observers are called during the after completion phase of the transaction, only when the transaction succeeds
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12570)
Hello! Python by Anthony Briggs(9915)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9778)
Dependency Injection in .NET by Mark Seemann(9338)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8297)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7073)
Microservices with Go by Alexander Shuiskov(6837)
Practical Design Patterns for Java Developers by Miroslav Wengner(6758)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6699)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Angular Projects - Third Edition by Aristeidis Bampakos(6102)
The Art of Crafting User Stories by The Art of Crafting User Stories(5630)
NetSuite for Consultants - Second Edition by Peter Ries(5565)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5371)
Kotlin in Action by Dmitry Jemerov(5062)
